package com.ktjiaoyu.crm.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktjiaoyu.crm.mapper.UserMapper;
import com.ktjiaoyu.crm.pojo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 用户登录
     * @param user
     * @return
     */
    @Override
    public User login(User user) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("usr_name",user.getUsrName());
        queryWrapper.eq("usr_password",user.getUsrPassword());
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public List<User> selectUserPages(Page<User> page, String usrName,Long roleId) {

        //条件构造器
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        if(usrName != null && !"".equals(usrName)){
            queryWrapper.like("usr_name",usrName);
        }
        if(roleId!=null && roleId!=0){
            queryWrapper.eq("usr_role_id",roleId);
        }

        return userMapper.selectUserPages(page,queryWrapper);
    }
}
